import { stringify } from 'qs';
import request from '../utils/request';
import paramUri from '../utils/params';

const baseUrl = 'http://127.0.0.1:8090/api';

export async function queryProjectNotice() {
  return request('/api/project/notice');
}

export async function queryActivities() {
  return request('/api/activities');
}

export async function queryRule(params) {
  return request(`/api/rule?${stringify(params)}`);
}

export async function removeRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'delete',
    },
  });
}

export async function addRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'post',
    },
  });
}

export async function fakeSubmitForm(params) {
  return request('/api/forms', {
    method: 'POST',
    body: params,
  });
}

export async function fakeChartData() {
  return request('/api/fake_chart_data');
}

export async function queryTags() {
  return request('/api/tags');
}

export async function queryBasicProfile() {
  return request('/api/profile/basic');
}

export async function queryAdvancedProfile() {
  return request('/api/profile/advanced');
}

export async function queryFakeList(params) {
  return request(`/api/fake_list?${stringify(params)}`);
}


export async function fakeMobileLogin(params) {
  return request('/api/login/mobile', {
    method: 'POST',
    body: params,
  });
}

export async function queryNotices() {
  return request('/api/notices');
}

// migrate api services
// login
export async function OrganLogin(params) {
  return request(`${baseUrl}/auth/login`, {
    method: 'POST',
    body: params,
  });
}

// register
export async function OrganRegister(params) {
  return request(`${baseUrl}/auth/register`, {
    method: 'POST',
    body: params,
  });
}

// get organ profile
export async function queryOrganProfile(params) {
  const paramUrl = paramUri(params);
  return request(`${baseUrl}/organ/profile?${paramUrl}`, {
    method: 'GET',
  });
}

// submit organ profile

export async function submitOrganProfile(params) {
  return request(`${baseUrl}/organ/profile/update`, {
    method: 'POST',
    body: params,
  });
}

// get asset attribute

export async function queryAttribute(params) {
  const paramUrl = paramUri(params);
  return request(`${baseUrl}/asset/attribute?${paramUrl}`, {
    method: 'GET',
  });
}

// add asset attribute

export async function addAttribute(params) {
  return request(`${baseUrl}/asset/attribute/add`, {
    method: 'POST',
    body: params,
  });
}

// get asset detail

export async function fetchAssetDetail(params) {
  const paramsUrl = paramUri(params);
  return request(`${baseUrl}/asset/detail?${paramsUrl}`, {
    method: 'GET',
  });
}

// get asset entity list

export async function fetchAssetList(params) {
  const paramUrl = paramUri(params);
  return request(`${baseUrl}/assets?${paramUrl}`, {
    method: 'GET',
  });
}

// add asset entity
export async function addAssetEntity(params) {
  return request(`${baseUrl}/asset/add`, {
    method: 'POST',
    body: params,
  });
}

// todo remove asset attribute
export async function removeAttribute(params) {
  return request(`${baseUrl}/asset/attribute/remove`, {
    method: 'POST',
    body: params,
  });
}

// get asset type detail info
export async function fetchTypeDetail(params) {
  const paramUrl = paramUri(params);
  return request(`${baseUrl}/asset/type/detail?${paramUrl}`, {
    method: 'GET',
  });
}

// add asset type
export async function addAssetType(params) {
  return request(`${baseUrl}/asset/type/add`, {
    method: 'POST',
    body: params,
  });
}

// add attribute to type
export async function addAttrToType(params) {
  return request(`${baseUrl}/asset/type/add-attr`, {
    method: 'POST',
    body: params,
  });
}

// get asset type list
export async function fetchAssetType(params) {
  const paramUrl = paramUri(params);
  return request(`${baseUrl}/asset/type${paramUrl}`, {
    method: 'GET',
  });
}

// get attribute according to type
export async function fetchTypeAttribute(params) {
  const paramUrl = paramUri(params);
  return request(`${baseUrl}/asset/type/attr?${paramUrl}`, {
    method: 'GET',
  });
}

